#include <iostream>
#include <vector>
#include <numeric>
#include <climits>

using namespace std;

// 2134. 最少交换次数来组合所有的 1 II
// https://leetcode.cn/problems/minimum-swaps-to-group-all-1s-together-ii/description/

class Solution
{
public:
    int minSwaps(vector<int> &nums)
    {
        int n = nums.size();
        int windowsLen = accumulate(nums.begin(), nums.end(), 0);
        if(windowsLen == n || windowsLen == 0){
            return 0;
        }
        int ans = INT_MAX;
        int left = 0;
        int curZeroCount = 0;
        for (int i = 0; i < 2 * n; i++)
        {
            if(nums[i % n] == 0){
                curZeroCount++;
            }
            if(i + left + 1 < windowsLen){
                continue;
            }
            ans = min(curZeroCount, ans);
            if(nums[left % n] == 0){
                curZeroCount--;
            }
            left++;
        }
        return ans;
    }
};

int main()
{
    return 0;
}